package com.yixiu.modules.db.druid;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

/**
 * druid数据源测试类
 *
 * 在类RenrenLearningApplication中运行main方法
 * 打开http://localhost:8080/druid 输入用户名admim,密码123456,登录查看日志
 * 打开http://localhost:8080/user  查看返回的信息
 *
 */

@RestController
public class TestDruidConfigController {

    // 根据名字druidDataSource从容器中获取bean
    @Resource
    private DruidDataSource druidDataSource;

    @RequestMapping("user")
    public List<Map<String, Object>> testDruid() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(druidDataSource);
        List<Map<String, Object>> list = jdbcTemplate.queryForList("SELECT * FROM user ", new Object[]{});
        return list;
    }


}